#include <stdio.h>
#include <string.h>

//第一种结构体数组的用法
union student
{
    int   number  ; //学号
    char  name[20] ; //保存姓名
    char  sex[10]  ; //male female
    int   age     ; //年龄
    float score   ; //成绩
};

int main(int argc, char const *argv[])
{
    union student stu1 ;

    stu1.number = 2;
    printf("stu1.number:      %d\n",stu1.number);
    printf("stu1.name  :      %s\n",stu1.name  );
    printf("stu1.sex   :      %s\n",stu1.sex   );
    printf("stu1.age   :      %d\n",stu1.age   );
    printf("stu1.score :      %f\n",stu1.score );

    strcpy(stu1.name,"zhao");
    printf("stu1.number:      %d\n",stu1.number);
    printf("stu1.name  :      %s\n",stu1.name  );
    printf("stu1.sex   :      %s\n",stu1.sex   );
    printf("stu1.age   :      %d\n",stu1.age   );
    printf("stu1.score :      %f\n",stu1.score );

    strcpy(stu1.sex,"female");
    printf("stu1.number:      %d\n",stu1.number);
    printf("stu1.name  :      %s\n",stu1.name  );
    printf("stu1.sex   :      %s\n",stu1.sex   );
    printf("stu1.age   :      %d\n",stu1.age   );
    printf("stu1.score :      %f\n",stu1.score );

    stu1.age = 21;
    printf("stu1.number:      %d\n",stu1.number);
    printf("stu1.name  :      %s\n",stu1.name  );
    printf("stu1.sex   :      %s\n",stu1.sex   );
    printf("stu1.age   :      %d\n",stu1.age   );
    printf("stu1.score :      %f\n",stu1.score );

    stu1.score =94;
    printf("stu1.number:      %d\n",stu1.number);
    printf("stu1.name  :      %s\n",stu1.name  );
    printf("stu1.sex   :      %s\n",stu1.sex   );
    printf("stu1.age   :      %d\n",stu1.age   );
    printf("stu1.score :      %f\n",stu1.score );

    return 0;
}
